package com.wwwarehouse.resource_center.fragment.information;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;

import com.wwwarehouse.resource_center.adapter.rules.MyPagerAdapter;
import com.wwwarehouse.resource_center.bean.goods.GoodsSelectLabelBean;
import com.wwwarehouse.resource_center.fragment.base.MyBaseViewPagerFragment;

import java.util.ArrayList;

/**
 * @author Joseph on 2017/9/26.
 *         <p/>
 *         商品标签
 */

public class InfomationShowLabelParentFragment extends MyBaseViewPagerFragment {

    ArrayList<GoodsSelectLabelBean.ListBean> laberData = new ArrayList<>();
    ArrayList<Fragment> fragmentList = new ArrayList<>();
    MyPagerAdapter mAdapter;
    int mNum = 30;
    private String title;

    @Override
    protected void loadDatas() {
        try {
            Bundle b = getArguments();
            laberData = b.getParcelableArrayList("laberData");
            title = b.getString("title");
            mActivity.setTitle(title);
        } catch (Exception e) {
            e.printStackTrace();
        }
        int count = 0;
        if (laberData.size() > mNum) {
            if ((laberData.size() - mNum) % mNum == 0) {
                count = (laberData.size() - mNum) / mNum;
            } else {
                count = (laberData.size() - mNum) / mNum + 1; // 总共显示多少张卡片
            }
        } else {
            count = 0;
        }

        for (int i = 0; i <= count; i++) {
            InfomationShowLabelListChildFragment categoryFragment = new InfomationShowLabelListChildFragment();
            Bundle bundle = new Bundle();
            bundle.putParcelableArrayList("data", laberData);
            bundle.putInt("pos", i);
            bundle.putInt("num", mNum);
            categoryFragment.setArguments(bundle);
            fragmentList.add(categoryFragment);
        }

        mAdapter = new MyPagerAdapter(getChildFragmentManager(), fragmentList);
        mCustomPager.setAdapter(mAdapter);
        mPagerInternal.setViewPager(mCustomPager, 0);

    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof InfomationShowLabelParentFragment)
            if (!TextUtils.isEmpty(title)) {
                mActivity.setTitle(title);
            }
    }
}
